package main

import (
	"boke/blogpb"
	"context"
	"fmt"
	"google.golang.org/grpc"
)

// 发起 获取blog请求
func update(cc *grpc.ClientConn, blogitem blogItem) (b blogItem, err error) {
	// read Blog
	fmt.Println("更新blog update the blog")

	c := blogpb.NewBlogServiceClient(cc)
	blogitem.Title = blogitem.Title + "这条数据被修改了update........"
	newblog := &blogpb.Blog{
		Id:       blogitem.ID,
		AuthorId: blogitem.AuthorID,
		Content:  blogitem.Content,
		Title:    blogitem.Title,
	}

	updateRes, err := c.UpdateBlog(context.Background(), &blogpb.UpdateBlogRequest{Blog: newblog})
	if err != nil {
		fmt.Printf("更新请求失败 Error happened while updating: %v \n", err)
		return
	}

	fmt.Println("更新完成 Blog was updated:", updateRes.Blog.GetId(), updateRes.Blog.GetAuthorId(), updateRes.Blog.GetContent(), updateRes.Blog.GetTitle())

	b = blogitem
	return
}
